﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
using Model;
using ExtAspNet;
using Manager.CustomerHelper;
namespace HealthSystem.sysAdmin
{
    public partial class OrgSingle : BasePage
    {
        HW_OrgUserManager manager = new HW_OrgUserManager();
        public override ModuleType Module
        {
            get
            {
                return ModuleType.OrgManager;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
            }
        }
        public void BindGrid()
        {
            string schoolcode = Request["orgcode"] as string;
            try
            {
                List<HW_OrgUser> list = manager.GetByOrgCode(schoolcode);
                Gird1.DataSource = list;
                Gird1.DataBind();
            }
            catch
            {
                ExtAspNet.Alert.Show("数据出错");
            }

        }

        public void Window1_Close(object sender, EventArgs e)
        {
            BindGrid();
        }
        protected void Row_click(object sender, ExtAspNet.GridCommandEventArgs e)
        {
            try
            {
                string username = Gird1.Rows[e.RowIndex].DataKeys[0] as string;
                if (e.CommandName == "reset")
                {
                    string pass = System.Configuration.ConfigurationManager.AppSettings["default"].ToString();
                    HW_OrgUser orguser=new HW_OrgUser ()
                    {
                        XX_UserName=username,
                        XX_Pass=pass,
                    };
                    manager.ResetPassWord(orguser);
                    Alert.Show("密码重置成功");
                }
                if (e.CommandName == "delete")
                {
                    manager.DeleteById(username);
                    BindGrid();
                    Alert.Show("删除成功");
                }
            }
            catch
            {
                ExtAspNet.Alert.Show("更新状态出错");
            }
        }
        protected void new_click(object sender, EventArgs e)
        {
            string url = "OrgSingle_Add.aspx?orgcode=" + Request["orgcode"] as string;
            ExtAspNet.PageContext.RegisterStartupScript(Window1.GetShowReference(url, "新增机构管理员"));
        }
    }
}